package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.order.handler.converter.JpaJsonToLogisticsAddressConverter;
import com.ssy.lingxi.order.model.bo.LogisticsAddressBO;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;

/**
 *  送货单-实体
 * @author ds
 * @date 2022/3/23
 * @version 2.0.0
 */
@Entity
@Table(schema = "public", name = "ord_delivery_order",
        indexes = {@Index(name = "ord_delivery_order_delivery_no_idx", columnList = "deliveryNo"),
                @Index(name = "ord_delivery_order_buyer_member_idx", columnList = "buyerMemberId, buyerRoleId"),
                @Index(name = "ord_delivery_order_source_type_source_no_idx", columnList = "sourceType, sourceNo"),
                @Index(name = "ord_delivery_order_vendor_member_idx", columnList = "vendorMemberId, vendorRoleId")})
public class DeliveryOrderDO implements Serializable {

    private static final long serialVersionUID = 2262925402025632928L;

    public DeliveryOrderDO() {
    }

    public DeliveryOrderDO(Long vendorMemberId, Long vendorRoleId, String vendorMemberName) {
        this.vendorMemberId = vendorMemberId;
        this.vendorRoleId = vendorRoleId;
        this.vendorMemberName = vendorMemberName;
    }

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_delivery_order_seq")
    @SequenceGenerator(sequenceName = "ord_delivery_order_seq", name = "ord_delivery_order_seq", allocationSize = 1)
    private Long id;

    /**
     * 送货单编号
     */
    @Column(columnDefinition = "varchar(20)")
    private String deliveryNo;

    /**
     * 来源类型：1-送货计划  2-送货通知
     */
    @Column
    private Integer sourceType;
    /**
     * 关联来源id：送货计划编号/送货通知编号
     */
    @Column(columnDefinition = "varchar(20)")
    private String sourceNo;

    /**
     * 通知单类型：1-B2B  2-SRM
     */
    @Column
    private Integer type;

    /**
     * 摘要
     */
    @Column(columnDefinition = "varchar(100)")
    private String digest;

    /**
     * 送货日期 yyyy-MM-dd
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime deliveryTime;

    /**
     * 送货开始时间 （HH:mm）
     */
    @Column(columnDefinition = "varchar(20)")
    private String deliveryStartTime;

    /**
     * 送货结束时间 （HH:mm）
     */
    @Column(columnDefinition = "varchar(20)")
    private String deliveryEndTime;

    /**
     * 买方（采购）会员Id
     */
    @Column
    private Long buyerMemberId;

    /**
     * 买方（采购）会员角色Id
     */
    @Column
    private Long buyerRoleId;

    /**
     * 采购会员名称
     */
    @Column(columnDefinition = "varchar(200)")
    private String buyerMemberName;

    /**
     * 卖方（供应）会员Id
     */
    @Column
    private Long vendorMemberId;

    /**
     * 卖方（供应）会员角色Id
     */
    @Column
    private Long vendorRoleId;

    /**
     * 采购会员名称
     */
    @Column(columnDefinition = "varchar(200)")
    private String vendorMemberName;

    /**
     * 外部状态 1-已提交 2-已收货 3-已作废
     */
    @Column
    private Integer outerStatus;

    /**
     * 备注
     */
    @Column(columnDefinition = "varchar(150)")
    private String remark;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime updateTime;

    /**
     * 配送方式: 1-物流（默认）, 2-自提, 3-无需配送
     */
    @Column
    private Integer deliveryType;

    /**
     * 发货时间 yyyy-MM-dd HH:mm
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime sendTime;

    /**
     * 发货地址
     */
    @Convert(converter = JpaJsonToLogisticsAddressConverter.class)
    @Column(columnDefinition = "jsonb")
    private LogisticsAddressBO deliverBO;
    /**
     * 收货地址
     */
    @Convert(converter = JpaJsonToLogisticsAddressConverter.class)
    @Column(columnDefinition = "jsonb")
    private LogisticsAddressBO receiverBO;
    /**
     * 物流公司
     */
    @Column(columnDefinition = "varchar(50)")
    private String logisticsCompany;

    /**
     * 物流公司id
     */
    @Column
    private Long logisticsCompanyId;
    /**
     * 物流单号
     */
    @Column(columnDefinition = "varchar(20)")
    private String logisticsNo;
    /**
     * 送货人信息
     */
    @Convert(converter = JpaJsonToLogisticsAddressConverter.class)
    @Column(columnDefinition = "jsonb")
    private LogisticsAddressBO executorBO;

    /**
     * 一对多双向关联计划送货物料
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "deliveryOrder", cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private Set<DeliveryOrderProductDO> deliveryOrderProductDOS;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDeliveryNo() {
        return deliveryNo;
    }

    public void setDeliveryNo(String deliveryNo) {
        this.deliveryNo = deliveryNo;
    }

    public Integer getSourceType() {
        return sourceType;
    }

    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }

    public String getSourceNo() {
        return sourceNo;
    }

    public void setSourceNo(String sourceNo) {
        this.sourceNo = sourceNo;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getDigest() {
        return digest;
    }

    public void setDigest(String digest) {
        this.digest = digest;
    }

    public LocalDateTime getDeliveryTime() {
        return deliveryTime;
    }

    public void setDeliveryTime(LocalDateTime deliveryTime) {
        this.deliveryTime = deliveryTime;
    }

    public String getDeliveryStartTime() {
        return deliveryStartTime;
    }

    public void setDeliveryStartTime(String deliveryStartTime) {
        this.deliveryStartTime = deliveryStartTime;
    }

    public String getDeliveryEndTime() {
        return deliveryEndTime;
    }

    public void setDeliveryEndTime(String deliveryEndTime) {
        this.deliveryEndTime = deliveryEndTime;
    }

    public Long getBuyerMemberId() {
        return buyerMemberId;
    }

    public void setBuyerMemberId(Long buyerMemberId) {
        this.buyerMemberId = buyerMemberId;
    }

    public Long getBuyerRoleId() {
        return buyerRoleId;
    }

    public void setBuyerRoleId(Long buyerRoleId) {
        this.buyerRoleId = buyerRoleId;
    }

    public String getBuyerMemberName() {
        return buyerMemberName;
    }

    public void setBuyerMemberName(String buyerMemberName) {
        this.buyerMemberName = buyerMemberName;
    }

    public Long getVendorMemberId() {
        return vendorMemberId;
    }

    public void setVendorMemberId(Long vendorMemberId) {
        this.vendorMemberId = vendorMemberId;
    }

    public Long getVendorRoleId() {
        return vendorRoleId;
    }

    public void setVendorRoleId(Long vendorRoleId) {
        this.vendorRoleId = vendorRoleId;
    }

    public String getVendorMemberName() {
        return vendorMemberName;
    }

    public void setVendorMemberName(String vendorMemberName) {
        this.vendorMemberName = vendorMemberName;
    }

    public Integer getOuterStatus() {
        return outerStatus;
    }

    public void setOuterStatus(Integer outerStatus) {
        this.outerStatus = outerStatus;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getDeliveryType() {
        return deliveryType;
    }

    public void setDeliveryType(Integer deliveryType) {
        this.deliveryType = deliveryType;
    }

    public LogisticsAddressBO getDeliverBO() {
        return deliverBO;
    }

    public void setDeliverBO(LogisticsAddressBO deliverBO) {
        this.deliverBO = deliverBO;
    }

    public LogisticsAddressBO getReceiverBO() {
        return receiverBO;
    }

    public void setReceiverBO(LogisticsAddressBO receiverBO) {
        this.receiverBO = receiverBO;
    }

    public String getLogisticsCompany() {
        return logisticsCompany;
    }

    public void setLogisticsCompany(String logisticsCompany) {
        this.logisticsCompany = logisticsCompany;
    }

    public Long getLogisticsCompanyId() {
        return logisticsCompanyId;
    }

    public void setLogisticsCompanyId(Long logisticsCompanyId) {
        this.logisticsCompanyId = logisticsCompanyId;
    }

    public String getLogisticsNo() {
        return logisticsNo;
    }

    public void setLogisticsNo(String logisticsNo) {
        this.logisticsNo = logisticsNo;
    }

    public LogisticsAddressBO getExecutorBO() {
        return executorBO;
    }

    public void setExecutorBO(LogisticsAddressBO executorBO) {
        this.executorBO = executorBO;
    }

    public Set<DeliveryOrderProductDO> getDeliveryOrderProductDOS() {
        return deliveryOrderProductDOS;
    }

    public void setDeliveryOrderProductDOS(Set<DeliveryOrderProductDO> deliveryOrderProductDOS) {
        this.deliveryOrderProductDOS = deliveryOrderProductDOS;
    }

    public LocalDateTime getSendTime() {
        return sendTime;
    }

    public void setSendTime(LocalDateTime sendTime) {
        this.sendTime = sendTime;
    }
}
